use md5::compute;

const PREFIX: &str = "axum";

/// md5加密
pub fn md5<D: AsRef<[u8]>>(data: D) -> String {
    let digest = compute(data);
    format!("{:x}", digest)
}

/// md5加盐加密
pub fn md5_salt<D: AsRef<[u8]>>(data: D, salt: D) -> String {
    let data: Vec<u8> = <str as AsRef<[u8]>>::as_ref(PREFIX)
        .iter()
        .chain(data.as_ref().iter())
        .chain(salt.as_ref().iter())
        .cloned()
        .collect();
    let digest = compute(data);
    format!("{:x}", digest)
}
